package com.lyhengtongwl.zqsnews.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lyhengtongwl.zqsnews.App;
import com.lyhengtongwl.zqsnews.R;
import com.lyhengtongwl.zqsnews.entity.NewsEntity;
import com.lyhengtongwl.zqsnews.utils.FTYUtils;
import com.makeramen.roundedimageview.RoundedImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

public class QDNewsAdapter extends BaseQuickAdapter<NewsEntity, BaseViewHolder> {
    private Activity activity;

    public QDNewsAdapter(Activity activity, List<NewsEntity> newsList) {
        super(R.layout.item_qd, newsList);
        this.activity = activity;
    }


    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(BaseViewHolder helper, NewsEntity item) {
        String title = item.getTitle();
        String linkUrl = item.getUrl();
        String money = item.getMoney();
        ((TextView) helper.getView(R.id.tv_title)).setText(title);
        ((TextView) helper.getView(R.id.tv_money)).setText("￥" + FTYUtils.fenToYuan(money).split("\\.")[0]);
        ((TextView) helper.getView(R.id.tv_forward_qd)).setText("转发赚钱");
//        (helper.getView(R.id.tv_forward_qd)).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                activity.startActivity(new Intent(activity, NewsWebDetailActivity.class).putExtra("url", item.getContentUrl()));
//            }
//        });
        Picasso.with(App.getContext()).load(linkUrl).placeholder(R.mipmap.error).error(R.mipmap.error).into((RoundedImageView) helper.getView(R.id.iv_preview));
    }
}
